﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace PagesList
{
    public partial class MonthTaizhang : UserControl
    {
        public MonthTaizhang()
        {
            InitializeComponent();
            //ShowData();
        }

        public void ShowData()
        {
            OleDbCommandBuilder oledbCmdBuilder;
            ds = new DataSet();
            string sql = null;
            connection = ConnectManager.GetSystemConnect();
            if (textBox1.Text == "")
            {
                sql = "select  * from ksd_CWyueshouru where datepart(month,送检日期)=datepart(month,'" + dateTimePicker1.Value + "')";
            }
            else
            {
                sql = "select * from ksd_CWyueshouru where 送检医院 like '%" + textBox1.Text + "%' and datepart(month,送检日期)=datepart(month,'" + dateTimePicker1.Value + "')";
            }
            try
            {
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
                oledbAdapter.Fill(ds);
                this.dataGridView1.DataSource = ds.Tables[0];

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private OleDbConnection connection;
        private OleDbDataAdapter oledbAdapter;
        private DataSet ds;

        private void MonthTaizhang_Resize(object sender, EventArgs e)
        {
            this.dataGridView1.Size = this.Size - new System.Drawing.Size(100, 100);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ExcelExportTool.DataGridViewToExcel(this.dataGridView1);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OleDbCommandBuilder oledbCmdBuilder;
            ds = new DataSet();
            string sql = null;
            connection = ConnectManager.GetSystemConnect();

            sql = "select  * from ksd_CWyueshouru where 项目编码 in (select jymddh from xt_jymd where jymdlb='MAYO') and datepart(month,送检日期)=datepart(month,'" + dateTimePicker1.Value + "')";
            try
            {
                oledbAdapter = new OleDbDataAdapter(sql, connection);
                oledbCmdBuilder = new OleDbCommandBuilder(oledbAdapter);
                oledbAdapter.Fill(ds);
                this.dataGridView1.DataSource = ds.Tables[0];

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
